package com.woniuxy.exam.controller;

import com.woniuxy.exam.entity.Manager;
import com.woniuxy.exam.service.ManagerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("manager")
@Slf4j
public class ManagerController {

    @Autowired
    ManagerService managerService ;

    @RequestMapping("/login")
    public String login(String username , String password, HttpServletRequest request){
        log.info("接收到的用户名和密码是:{},{}",username,password);

        Manager manager = managerService.login(username);
        if (manager == null) {
            request.setAttribute("errorInfo","账号不存在!");
            return "login" ;
        }else {
            if (manager.getPassword().equals(password)) {
                //登录成功
                request.getSession().setAttribute("userInfo",manager);
                //重定向查询 图书
                return "redirect:/book/list";
            }else {
                request.setAttribute("errorInfo","密码错误!");
                return "login" ;
            }
        }
    }
}
